<?php
namespace common\queue\jobs;

use think\queue\Job;
use common\queue\JobAbstract;

use common\service\ChainService;
use common\service\QueueService;
use common\model\sell66\BotInv;

use think\Exception;
use think\Log;

class AssetJob extends JobAbstract
{
	public function assetJob(Job $job, $botInvId)
	{
		try {
			$info = BotInv::getInfoByBotInvId($botInvId);
			if (!$info) {
				throw new Exception('query bot inv failed, botinvid:'.$botInvId);
			}

			if ($info['issue_id']) {
				throw new Exception('query issue id is not empty, botinvid:'.$botInvId);
			}

			$res = ChainService::getInstance()->getIssueId($botInvId);
			if (!$res) {
				QueueService::getInstance()->setAdapter('AssetJob')->assetJob($botInvId);
				// get issue_id queue
				throw new Exception('get issue id failed, botinvid:'.$botInvId);
			}

			$job->delete();
			echo 'get issue id success, botinvid:'.$botInvId."\r\n";
		} catch (Exception $e) {
			echo $e->getMessage()."\r\n";
			$job->delete();
			return false;
		}
	}
}
